package com.mxf.code.redisson_demo;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : [mxf]
 * @version : [v1.0]
 * @className : RedissonController
 * @description : [描述说明该类的功能]
 * @createTime : [2022/10/9 18:14]
 * @updateUser : [mxf]
 * @updateTime : [2022/10/9 18:14]
 * @updateRemark : [描述说明本次修改内容]
 */
@RestController
public class RedissonController {

    @Autowired
    private RedissonClient redissonClient;

    private DistributedLocker distributedLocker;

    @Autowired
    public void setDistributedLocker(DistributedLocker distributedLocker) {
        this.distributedLocker = distributedLocker;
    }

    @GetMapping(value = "/redisson/{key}")
    public String redissonTest(@PathVariable("key") String lockKey) {
        RLock lock = redissonClient.getLock(lockKey);
        try {
            lock.lock();
            Thread.sleep(10000);
        } catch (Exception e) {

        } finally {
            lock.unlock();
        }
        return "已解锁";
    }



}

